package com.onedriver;

import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.xmlbeans.XmlException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.xwpf.usermodel.XWPFRun;

import java.io.FileOutputStream;
import java.io.IOException;

public class HtmlToWordConverter {
    public static void main(String[] args) {
        String htmlContent = "<html><body><p>Hello, World!</p></body></html>";
        try ( XWPFDocument doc = new XWPFDocument()){

        XWPFParagraph p = doc.createParagraph();
        XWPFRun r = p.createRun();

        // 将HTML内容转换为XHTML，然后通过POI写入Word文档
        r.setText(htmlContent, 0);

        try (FileOutputStream out = new FileOutputStream("output2.docx")) {
            doc.write(out);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        }catch (IOException ex) {
            throw new RuntimeException(ex);
        }


    }
}
